package com.globalwave.pos.sale.entity;

import javax.persistence.*;

import org.hibernate.annotations.GenericGenerator;

import com.globalwave.base.BaseEntity;
import com.globalwave.pos.payment.entity.RecievableDetailInf;


/**
 * The persistent class for the INVENTORY_ON_HAND_BALANCE database table.
 * 
 */
@Entity
@Table(name="Sales_Order_Line")
public class SalesOrderLine extends BaseEntity implements RecievableDetailInf{
	private static final long serialVersionUID = 1L;

	
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="increment")
    @GenericGenerator(name="Sales_Order_Line_ID_SEQ", strategy = "increment")
   private Long      id                  ;
   private Long      sales_order_id      ;
   private Integer   line_number         ;
   private String    type_               ;
   private Long      item_number         ;
   private String    item_sku            ;
   private Long      stock_item_number   ;
   private String    item_desc    ;
   private String    item_class_code     ;
   private Double    unit_orginal_price  ;
   private Double    unit_discount_price ;
   private Double    unit_price1         ;
   private Double    unit_price2         ;
   private Double    unit_gift_point     ;
   private Double    unit_nation_tax     ;
   private Double    unit_location_tax   ;
   private String    currency_code       ;
   private String    unit_code           ;
   private Integer   order_quantity      ;
   private Integer   returned_quantity   ;
   private Integer   shipped_quantity_total ;
   private Integer   shipped_quantity_1 ;
   private Integer   shipped_quantity_2 ;
   private Integer   shipped_quantity_3 ;
   private Integer   shipped_quantity_4 ;
   private Integer   shipped_quantity_5 ;
   private Integer   tna_quantity       ;
   private Short     returnable_flag    ;
   private String    promotion_code     ;
   private String    promotion_flag     ;
   private Short     status_            ;
   private Integer   sale_date ;
   
    @Transient
    private SalesOrder salesOrder ;
    
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Long getSales_order_id() {
		return sales_order_id;
	}
	public void setSales_order_id(Long sales_order_id) {
		this.sales_order_id = sales_order_id;
	}
	public Integer getLine_number() {
		return line_number;
	}
	public void setLine_number(Integer line_number) {
		this.line_number = line_number;
	}
	public String getType_() {
		return type_;
	}
	public void setType_(String type_) {
		this.type_ = type_;
	}
	public Long getItem_number() {
		return item_number;
	}
	public void setItem_number(Long item_number) {
		this.item_number = item_number;
	}
	public String getItem_sku() {
		return item_sku;
	}
	public void setItem_sku(String item_sku) {
		this.item_sku = item_sku;
	}
	public Long getStock_item_number() {
		return stock_item_number;
	}
	public void setStock_item_number(Long stock_item_number) {
		this.stock_item_number = stock_item_number;
	}
	public String getItem_desc() {
		return item_desc;
	}
	public void setItem_desc(String item_desc) {
		this.item_desc = item_desc;
	}
	public String getItem_class_code() {
		return item_class_code;
	}
	public void setItem_class_code(String item_class_code) {
		this.item_class_code = item_class_code;
	}
	public Double getUnit_orginal_price() {
		return unit_orginal_price;
	}
	public void setUnit_orginal_price(Double unit_orginal_price) {
		this.unit_orginal_price = unit_orginal_price;
	}
	public Double getUnit_discount_price() {
		return unit_discount_price;
	}
	public void setUnit_discount_price(Double unit_discount_price) {
		this.unit_discount_price = unit_discount_price;
	}
	public Double getUnit_price1() {
		return unit_price1;
	}
	public void setUnit_price1(Double unit_price1) {
		this.unit_price1 = unit_price1;
	}
	public Double getUnit_price2() {
		return unit_price2;
	}
	public void setUnit_price2(Double unit_price2) {
		this.unit_price2 = unit_price2;
	}
	public Double getUnit_gift_point() {
		return unit_gift_point;
	}
	public void setUnit_gift_point(Double unit_gift_point) {
		this.unit_gift_point = unit_gift_point;
	}
	public Double getUnit_nation_tax() {
		return unit_nation_tax;
	}
	public void setUnit_nation_tax(Double unit_nation_tax) {
		this.unit_nation_tax = unit_nation_tax;
	}
	public Double getUnit_location_tax() {
		return unit_location_tax;
	}
	public void setUnit_location_tax(Double unit_location_tax) {
		this.unit_location_tax = unit_location_tax;
	}
	public String getCurrency_code() {
		return currency_code;
	}
	public void setCurrency_code(String currency_code) {
		this.currency_code = currency_code;
	}
	public String getUnit_code() {
		return unit_code;
	}
	public void setUnit_code(String unit_code) {
		this.unit_code = unit_code;
	}
	public Integer getOrder_quantity() {
		return order_quantity;
	}
	public void setOrder_quantity(Integer order_quantity) {
		this.order_quantity = order_quantity;
	}
	public Integer getReturned_quantity() {
		return returned_quantity;
	}
	public void setReturned_quantity(Integer returned_quantity) {
		this.returned_quantity = returned_quantity;
	}
	
	public Short getReturnable_flag() {
		return returnable_flag;
	}
	public void setReturnable_flag(Short returnable_flag) {
		this.returnable_flag = returnable_flag;
	}
	public String getPromotion_code() {
		return promotion_code;
	}
	public void setPromotion_code(String promotion_code) {
		this.promotion_code = promotion_code;
	}
	public String getPromotion_flag() {
		return promotion_flag;
	}
	public void setPromotion_flag(String promotion_flag) {
		this.promotion_flag = promotion_flag;
	}
	public SalesOrder getSalesOrder() {
		return salesOrder;
	}
	public void setSalesOrder(SalesOrder salesOrder) {
		this.salesOrder = salesOrder;
		if (salesOrder != null) {
			this.sales_order_id = salesOrder.getId() ;
		}
	}
	public Integer getShipped_quantity_total() {
		return shipped_quantity_total;
	}
	public void setShipped_quantity_total(Integer shipped_quantity_total) {
		this.shipped_quantity_total = shipped_quantity_total;
		this.addInclusions("shipped_quantity_total") ;
	}
	public Integer getShipped_quantity_1() {
		return shipped_quantity_1;
	}
	public void setShipped_quantity_1(Integer shipped_quantity_1) {
		this.shipped_quantity_1 = shipped_quantity_1;
	}
	public Integer getShipped_quantity_2() {
		return shipped_quantity_2;
	}
	public void setShipped_quantity_2(Integer shipped_quantity_2) {
		this.shipped_quantity_2 = shipped_quantity_2;
	}
	public Integer getShipped_quantity_3() {
		return shipped_quantity_3;
	}
	public void setShipped_quantity_3(Integer shipped_quantity_3) {
		this.shipped_quantity_3 = shipped_quantity_3;
	}
	public Integer getShipped_quantity_4() {
		return shipped_quantity_4;
	}
	public void setShipped_quantity_4(Integer shipped_quantity_4) {
		this.shipped_quantity_4 = shipped_quantity_4;
	}
	public Integer getShipped_quantity_5() {
		return shipped_quantity_5;
	}
	public void setShipped_quantity_5(Integer shipped_quantity_5) {
		this.shipped_quantity_5 = shipped_quantity_5;
	}
	public Integer getTna_quantity() {
		return tna_quantity;
	}
	public void setTna_quantity(Integer tna_quantity) {
		this.tna_quantity = tna_quantity;
		this.addInclusions("tna_quantity") ;
	}
	public Short getStatus_() {
		return status_;
	}
	public void setStatus_(Short status_) {
		this.status_ = status_;
	}
	
	public Integer getSale_date() {
		return sale_date;
	}
	public void setSale_date(Integer sale_date) {
		this.sale_date = sale_date;
	}
	public Integer getShipped_quantity() {
		short index = this.getSalesOrder().getShipment_times() ;
		if (index == 1) {
			return shipped_quantity_1;
		}
		if (index == 2) {
			return shipped_quantity_2;
		}
		if (index == 3) {
			return shipped_quantity_3;
		}
		if (index == 4) {
			return shipped_quantity_4;
		}
		if (index == 5) {
			return shipped_quantity_5;
		}
		return null;
	}
	

	
	public void setShipped_quantity(Integer quantity) {
		short index = this.getSalesOrder().getShipment_times() ;
		
		if (index == 1) {
			shipped_quantity_1 = quantity; 
			this.addInclusions("shipped_quantity_1") ;
		}
		if (index == 2) {
			shipped_quantity_2 = quantity; 
			this.addInclusions("shipped_quantity_2") ;
		}
		if (index == 3) {
			shipped_quantity_3 = quantity; 
			this.addInclusions("shipped_quantity_3") ;
		}
		if (index == 4) {
			shipped_quantity_4 = quantity; 
			this.addInclusions("shipped_quantity_4") ;
		}
		if (index == 5) {
			shipped_quantity_5 = quantity; 
			this.addInclusions("shipped_quantity_5") ;
		}


		this.addInclusions("shipped_quantity_total") ;
		shipped_quantity_total += quantity; 
		
	}
	
	public Double getRecievable_amount() {
		return this.unit_discount_price * (this.order_quantity - this.tna_quantity);
	}
	
	@Override
	public SalesOrderLine clone() throws CloneNotSupportedException {
		return (SalesOrderLine)super.clone();
	}

}